/**
 * @author yunshang
 */
var QQMapWX = require('../../utils/qqmap-wx-jssdk.min.js');
var WxNotificationCenter = require('../../utils/WxNotificationCenter.js');
var that;
var qqmapsdk;
var latitude;
var longitude;
Page({
  onLoad: function (options) {
    that = this;
    qqmapsdk = new QQMapWX({
      key: 'ELKBZ-SJMCO-6S2WC-SGNUN-N3542-Y2F7J'
    });
   // that.reloadCurrent();

    wx.getLocation({
      type: 'wgs84',
      success: function (res) {
        // 调用接口
        qqmapsdk.reverseGeocoder({
          location: {
            latitude: res.latitude,
            longitude: res.longitude
          },
          success: function (res) {
            // 渲染给页面
            that.setData({
              address: res.result.formatted_addresses.recommend,
              result: res.result.pois,
              city: res.result.address_component.city
            });
            console.log(res);
          },
        });
      }
    });
  },
  addressTapped: function (e) {
    var title = e.currentTarget.dataset.title;
    // 取出点中的地址，然后使用WxNotification回传给首页
    WxNotificationCenter.postNotificationName("addressSelectedNotification", title);
    wx.navigateBack();
  },
  geoTapped: function () {
    var title = that.data.address;
    WxNotificationCenter.postNotificationName("addressSelectedNotification", title);
    wx.navigateBack();

  },

})